/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using System;
using VMukti.DataAccess;
using VMukti.Common;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using VMukti.Business.CommonDataContracts;
using VMuktiAPI;

namespace VMukti.Business
{
    public class ClsUser : ClsBaseObject
    {
        #region Fields

        private int _ID = VMukti.Common.ClsConstants.NullInt;
        private string _DisplayName = VMukti.Common.ClsConstants.NullString;
        private int _RoleID = VMukti.Common.ClsConstants.NullInt;
        private string _FName = VMukti.Common.ClsConstants.NullString;
        private string _LName = VMukti.Common.ClsConstants.NullString;
        private string _EMail = VMukti.Common.ClsConstants.NullString;
        private string _PassWord = VMukti.Common.ClsConstants.NullString;
        private bool _IsActive;
        private DateTime _CreatedDate = VMukti.Common.ClsConstants.NullDateTime;
        private int _CreatedBy = VMukti.Common.ClsConstants.NullInt;
        private DateTime _ModifiedDate = VMukti.Common.ClsConstants.NullDateTime;
        private int _ModifiedBy = VMukti.Common.ClsConstants.NullInt;

        private float _RatePerHour = VMukti.Common.ClsConstants.NullFloat;
        private float _OverTimeRate = VMukti.Common.ClsConstants.NullFloat;
        private float _DoubleRatePerHour = VMukti.Common.ClsConstants.NullFloat;
        private float _DoubleOverTimeRate = VMukti.Common.ClsConstants.NullFloat;


        private long _CampaignID = VMukti.Common.ClsConstants.NullLong;
        private long _GroupID = VMukti.Common.ClsConstants.NullLong;
        private long _ActivityID = VMukti.Common.ClsConstants.NullLong;

        private string _CampaignName = VMukti.Common.ClsConstants.NullString;
        private string _GroupName = VMukti.Common.ClsConstants.NullString;
        private string _RoleName = VMukti.Common.ClsConstants.NullString;

        private DateTime _StartTime = VMukti.Common.ClsConstants.NullDateTime;
        private DateTime _EndTime = VMukti.Common.ClsConstants.NullDateTime;


        #endregion 

        #region Properties

        public long CampaignID
        {
            get { return _CampaignID; }
            set { _CampaignID = value; }
        }

        public long GroupID
        {
            get { return _GroupID; }
            set { _GroupID = value; }
        }

        public long ActivityID
        {
            get { return _ActivityID; }
            set { _ActivityID = value; }
        }

        public DateTime StartTime
        {
            get
            {
                return _StartTime;
            }
            set
            {
                _StartTime = value;
            }
        }

        public DateTime EndTime
        {
            get
            {
                return _EndTime;
            }
            set
            {
                _EndTime = value;
            }
        }

        public string CampaignName
        {
            get { return _CampaignName; }
            set { _CampaignName = value; }
        }

        public string GroupName
        {
            get { return _GroupName; }
            set { _GroupName = value; }
        }
        public string RoleName
        {
            get { return _RoleName; }
            set { _RoleName = value; }
        }

        public int ID
        {
            get{return _ID;}
            set{_ID = value;}
        }

        public string DisplayName
        {
            get { return _DisplayName; }
            set { _DisplayName = value;}
        }

        public int RoleID
        {
            get { return _RoleID; }
            set { _RoleID = value; }
        }

        public string FName
        {
            get { return _FName; }
            set { _FName = value; }
        }

        public string LName
        {
            get { return _LName; }
            set { _LName = value; }
        }

        public string EMail
        {
            get { return _EMail; }
            set { _EMail = value; }
        }

        public string PassWord
        {
            get { return _PassWord; }
            set { _PassWord = value; }
        }

        public bool IsActive
        {
            get { return _IsActive; }
            set { _IsActive = value; }
        }

        public DateTime CreatedDate
        {
            get { return _CreatedDate;}
            set { _CreatedDate = value; }
        }

        public int CreatedBy
        {
            get { return _CreatedBy; }
            set { _CreatedBy = value; }
        }

        public DateTime ModifiedDate
        {
            get { return _ModifiedDate; }
            set { _ModifiedDate = value; }
        }

        public int ModifiedBy
        {
            get { return _ModifiedBy; }
            set { _ModifiedBy = value; }
        }

        public float RatePerHour
        {
            get { return _RatePerHour; }
            set { _RatePerHour = value; }
        }

        public float OverTimeRate
        {
            get { return _OverTimeRate; }
            set { _OverTimeRate = value; }
        }

        public float DoubleRatePerHour
        {
            get { return _DoubleRatePerHour; }
            set { _DoubleRatePerHour = value; }
        }

        public float DoubleOverTimeRate
        {
            get { return _DoubleOverTimeRate; }
            set { _DoubleOverTimeRate = value; }
        }

        #endregion 

        #region Methods

        public override bool MapData(DataRow row)
        {
            try
            {
                ID = GetInt(row, "ID");
                DisplayName = GetString(row, "DisplayName");
                RoleID = GetInt(row, "RoleID");
                FName = GetString(row, "FirstName");
                LName = GetString(row, "LastName");
                EMail = GetString(row, "EMail");
                PassWord = GetString(row, "Password");
                IsActive = GetBool(row, "IsActive");
                CreatedDate = GetDateTime(row, "CreatedDate");
                CreatedBy = GetInt(row, "CreatedBy");
                ModifiedDate = GetDateTime(row, "ModifiedDate");
                ModifiedBy = GetInt(row, "ModifiedBy");

                RatePerHour = GetFloat(row, "RatePerHour");
                OverTimeRate = GetFloat(row, "OverTimeRate");
                DoubleRatePerHour = GetFloat(row, "DoubleRatePerHour");
                DoubleOverTimeRate = GetFloat(row, "DoubleOverTimeRate");

                return base.MapData(row);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--MapData()--");               
                return false;
            }
        }

        public static ClsUser GetByGroupID(int ID)
        {
            try
            {
                ClsUser obj = new ClsUser();
                if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
                {
                    
                    List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                    clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                    objInfo.Direction = "Input";
                    objInfo.PName = "@pID";
                    objInfo.PValue = ID;
                    objInfo.PDBType = "Int";
                    objInfo.PSize = 200;

                    lstSP.Add(objInfo);

                    clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                    CSqlInfo.objParam = lstSP;
                    DataSet ds;
                    try
                    {
                        ds = VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGUserInfoPayroll", CSqlInfo).dsInfo;
                    }
                    catch (System.ServiceModel.EndpointNotFoundException e)
                    {
                        e.Data.Add("My Key", " GetByGroupID(int ID)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        ds = VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGUserInfoPayroll", CSqlInfo).dsInfo;
                    }
                    catch (System.ServiceModel.CommunicationException e)
                    {
                        e.Data.Add("My Key", " GetByGroupID(int ID)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        ds = VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGUserInfoPayroll", CSqlInfo).dsInfo;
                    }
                   
                    if (!obj.MapData(ds.Tables[0])) obj = null;
                }
                else
                {
                    DataSet ds = new VMukti.DataAccess.ClsUserDataService().User_GetByID(ID);

                    if (!obj.MapData(ds.Tables[0])) obj = null;
                }
                return obj;
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--GetByGroupId()--");
                
                return null;
            }
        }

        public void MapData4Campaign(DataRow row)
        {
            CampaignID = GetLong(row, "CampaignID");
            GroupID = GetLong(row, "GroupID");
            CampaignName = GetString(row, "CampaignName");
            GroupName = GetString(row, "GroupName");
            RoleName = GetString(row, "RoleName");
        }

        public static ClsUser GetByUNamePass(string UName, string Password, ref bool Result)
        {
            try
            {
                ClsUser obj = new ClsUser();
                if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
                {                  

                    List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                    clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                    objInfo.Direction = "Input";
                    objInfo.PName = "@pID";
                    objInfo.PValue = -1;
                    objInfo.PDBType = "Int";
                    objInfo.PSize = 200;

                    clsSqlParametersInfo objInfo2 = new clsSqlParametersInfo();
                    objInfo2.Direction = "Input";
                    objInfo2.PName = "@pUName";
                    objInfo2.PValue = UName;
                    objInfo2.PDBType = "NVarChar";
                    objInfo2.PSize = 200;

                    clsSqlParametersInfo objInfo3 = new clsSqlParametersInfo();
                    objInfo3.Direction = "Input";
                    objInfo3.PName = "@pPass";
                    objInfo3.PValue = Password;
                    objInfo3.PDBType = "NVarChar";
                    objInfo3.PSize = 200;

                    clsSqlParametersInfo objInfo4 = new clsSqlParametersInfo();
                    objInfo4.Direction = "InputOutput";
                    objInfo4.PName = "@pResult";
                    objInfo4.PValue = false;
                    objInfo4.PDBType = "Bit";
                    objInfo4.PSize = 200;                                                        
                    

                    lstSP.Add(objInfo);
                    lstSP.Add(objInfo2);
                    lstSP.Add(objInfo3);
                    lstSP.Add(objInfo4);
                    
                    clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                    CSqlInfo.objParam = lstSP;

                    DataSet ds;
                    try
                    {
                        ds = VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGUserInfoPayroll", CSqlInfo).dsInfo;
                    }
                    catch (System.ServiceModel.EndpointNotFoundException e)
                    {
                        e.Data.Add("My Key", " GetByUNamePass(string UName, string Password, ref bool Result)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        ds = VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGUserInfoPayroll", CSqlInfo).dsInfo;
                    }
                    catch (System.ServiceModel.CommunicationException e)
                    {
                        e.Data.Add("My Key", " GetByUNamePass(string UName, string Password, ref bool Result)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        ds = VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGUserInfoPayroll", CSqlInfo).dsInfo;
                    }

                    if (!obj.MapData(ds.Tables[0])) obj = null;

                    if (obj != null && ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
                    {
                        obj.MapData4Campaign(ds.Tables[1].Rows[0]);
                    }

                }
                else
                {
                    DataSet ds = new VMukti.DataAccess.ClsUserDataService().User_GetByUNamePass(UName, Password, ref Result);

                    if (!obj.MapData(ds.Tables[0])) obj = null;

                    if (obj != null && ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
                    {
                        obj.MapData4Campaign(ds.Tables[1].Rows[0]);
                    }
                }
                return obj;
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--GetByUNamePass()--");
                return null;
            }
        }

        public static void Logout(Int64 UserID)
        {
            try
            {               
                if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
                {

                    List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                    clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                    objInfo.Direction = "Input";
                    objInfo.PName = "@pID";
                    objInfo.PValue = -1;
                    objInfo.PDBType = "BigInt";
                    objInfo.PSize = 200;

                    lstSP.Add(objInfo);

                   
                    clsSqlParametersInfo objInfo2 = new clsSqlParametersInfo();
                    objInfo2.Direction = "Input";
                    objInfo2.PName = "@pUserID";
                    objInfo2.PValue = UserID;
                    objInfo2.PDBType = "BigInt";
                    objInfo2.PSize = 200;

                    lstSP.Add(objInfo2);


                    clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                    CSqlInfo.objParam = lstSP;

                    try
                    {
                        VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteNonQuery("spDOnlineUsers", CSqlInfo);
                    }
                    catch (System.ServiceModel.EndpointNotFoundException e)
                    {
                        e.Data.Add("My Key", " Logout(Int64 UserID)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteNonQuery("spDOnlineUsers", CSqlInfo);
                    }
                    catch (System.ServiceModel.CommunicationException e)
                    {
                        e.Data.Add("My Key", "Logout(Int64 UserID)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteNonQuery("spDOnlineUsers", CSqlInfo);
                    }  
                }
                else
                {

                    new VMukti.DataAccess.ClsUserDataService().User_LogOff(UserID);
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--LogOut()--");
             
            }
        }

        public static void Delete(int ID)
        {
            try
            {
                Delete(ID, null);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--Delete(int)--");
             
            }
        }

        public static void Delete(int ID, IDbTransaction txn)
        {
            try
            {                
                if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
                {

                    List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                    clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                    objInfo.Direction = "Input";
                    objInfo.PName = "@pID";
                    objInfo.PValue = ID;
                    objInfo.PDBType = "Int";
                    objInfo.PSize = 200;

                    lstSP.Add(objInfo);                   

                    clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                    CSqlInfo.objParam = lstSP;


                    try
                    {
                        VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteNonQuery("spDOnlineUsers", CSqlInfo);
                    }
                    catch (System.ServiceModel.EndpointNotFoundException e)
                    {
                        e.Data.Add("My Key", "Delete(int ID, IDbTransaction txn)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteNonQuery("spDOnlineUsers", CSqlInfo);
                    }
                    catch (System.ServiceModel.CommunicationException e)
                    {
                        e.Data.Add("My Key", "Delete(int ID, IDbTransaction txn)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteNonQuery("spDOnlineUsers", CSqlInfo);
                    }  
                    
                }
                else
                {
                    new VMukti.DataAccess.ClsUserDataService(txn).User_Delete(ID);
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--Delete(int64,IDbTransaction)--");
            }
        }

        public void Delete()
        {
            try
            {
                Delete(ID);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--Delete()--");
            }
        }

        public void Delete(IDbTransaction txn)
        {
            try
            {
                Delete(ID, txn);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--Delete(IDbTransaction)--");

            }
        }

        public int Save()
        {
            try
            {
               return(Save(null));
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--Save()--");
                return 0;
            }
        }

        public int Save(IDbTransaction txn)
        {
            try
            {
                /////////===============================================================
                //ExecuteNonQuery(out cmd, "spAEUserInfoPayroll",
                //    CreateParameter("@pID", SqlDbType.Int, ID),
                //    CreateParameter("@pDisplayName", SqlDbType.NVarChar, displayame, 100),
                //    CreateParameter("@pRoleID", SqlDbType.BigInt, roleID),
                //    CreateParameter("@pFirstName", SqlDbType.NVarChar, firstName, 50),
                //    CreateParameter("@pLastName", SqlDbType.NVarChar, lastName, 50),
                //    CreateParameter("@pEMail", SqlDbType.NVarChar, eMail, 256),
                //    CreateParameter("@pPassword", SqlDbType.NVarChar, password, 50),
                //    CreateParameter("@pIsActive", SqlDbType.Bit, isActive),
                //    CreateParameter("@pByUserID", SqlDbType.BigInt, byUserId),
                //    CreateParameter("@pRatePerHour", SqlDbType.Float, ratePerHour),
                //    CreateParameter("@pOverTimeRate", SqlDbType.Float, overTimeRate),
                //    CreateParameter("@pDoubleRatePerHour", SqlDbType.Float, doubleRatePerHour),
                //    CreateParameter("@pDoubleOverTimeRate", SqlDbType.Float, doubleOverTimeRate),
                //    CreateParameter("@pReturnId", SqlDbType.BigInt, ParameterDirection.Output));
                //int retID = int.Parse(cmd.Parameters["@pReturnId"].Value.ToString());
                //_ID, _DisplayName, _RoleID, _FName, _LName, _EMail, _PassWord, _IsActive, _ModifiedBy, _RatePerHour, _OverTimeRate, _DoubleRatePerHour, _DoubleOverTimeRate
                //cmd.Dispose();
                //return retID;

                if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
                {

                    List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                    clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                    objInfo.Direction = "Input";
                    objInfo.PName = "@pID";
                    objInfo.PValue = _ID;
                    objInfo.PDBType = "Int";
                    objInfo.PSize = 200;

                    clsSqlParametersInfo objInfo2 = new clsSqlParametersInfo();
                    objInfo2.Direction = "Input";
                    objInfo2.PName = "@pDisplayName";
                    objInfo2.PValue = _DisplayName;
                    objInfo2.PDBType = "NVarChar";
                    objInfo2.PSize = 100;

                    clsSqlParametersInfo objInfo3 = new clsSqlParametersInfo();
                    objInfo3.Direction = "Input";
                    objInfo3.PName = "@pRoleID";
                    objInfo3.PValue = _RoleID;
                    objInfo3.PDBType = "BigInt";
                    objInfo3.PSize = 200;

                    clsSqlParametersInfo objInfo4 = new clsSqlParametersInfo();
                    objInfo4.Direction = "Input";
                    objInfo4.PName = "@pFirstName";
                    objInfo4.PValue = _FName;
                    objInfo4.PDBType = "NVarChar";
                    objInfo4.PSize = 50;

                    clsSqlParametersInfo objInfo5 = new clsSqlParametersInfo();
                    objInfo5.Direction = "Input";
                    objInfo5.PName = "@pLastName";
                    objInfo5.PValue = _LName;
                    objInfo5.PDBType = "NVarChar";
                    objInfo5.PSize = 50;

                    clsSqlParametersInfo objInfo6 = new clsSqlParametersInfo();
                    objInfo6.Direction = "Input";
                    objInfo6.PName = "@pEMail";
                    objInfo6.PValue = _EMail;
                    objInfo6.PDBType = "NVarChar";
                    objInfo6.PSize = 256;

                    
                    clsSqlParametersInfo objInfo7 = new clsSqlParametersInfo();
                    objInfo7.Direction = "Input";
                    objInfo7.PName = "@pPassword";
                    objInfo7.PValue = _PassWord;
                    objInfo7.PDBType = "NVarChar";
                    objInfo7.PSize = 50;

                    clsSqlParametersInfo objInfo8 = new clsSqlParametersInfo();
                    objInfo8.Direction = "Input";
                    objInfo8.PName = "@pIsActive";
                    objInfo8.PValue = _IsActive;
                    objInfo8.PDBType = "Bit";
                    objInfo8.PSize = 200;

                    clsSqlParametersInfo objInfo9 = new clsSqlParametersInfo();
                    objInfo9.Direction = "Input";
                    objInfo9.PName = "@pByUserID";
                    objInfo9.PValue = _ModifiedBy;
                    objInfo9.PDBType = "BigInt";
                    objInfo9.PSize = 200;

                    clsSqlParametersInfo objInfo10 = new clsSqlParametersInfo();
                    objInfo10.Direction = "Input";
                    objInfo10.PName = "@pRatePerHour";
                    objInfo10.PValue = _RatePerHour;
                    objInfo10.PDBType = "Float";
                    objInfo10.PSize = 200;

                    clsSqlParametersInfo objInfo11 = new clsSqlParametersInfo();
                    objInfo11.Direction = "Input";
                    objInfo11.PName = "@pOverTimeRate";
                    objInfo11.PValue = _OverTimeRate;
                    objInfo11.PDBType = "Float";
                    objInfo11.PSize = 200;

                    clsSqlParametersInfo objInfo12 = new clsSqlParametersInfo();
                    objInfo12.Direction = "Input";
                    objInfo12.PName = "@pDoubleRatePerHour";
                    objInfo12.PValue = _DoubleRatePerHour;
                    objInfo12.PDBType = "Float";
                    objInfo12.PSize = 200;

                    clsSqlParametersInfo objInfo13 = new clsSqlParametersInfo();
                    objInfo13.Direction = "Input";
                    objInfo13.PName = "@pDoubleOverTimeRate";
                    objInfo13.PValue = _DoubleOverTimeRate;
                    objInfo13.PDBType = "Float";
                    objInfo13.PSize = 200;

                    clsSqlParametersInfo objInfo14 = new clsSqlParametersInfo();
                    objInfo14.Direction = "Output";
                    objInfo14.PName = "@pReturnId";
                    objInfo14.PValue = -1;
                    objInfo14.PDBType = "BigInt";
                    objInfo14.PSize = 200;
                    

                    lstSP.Add(objInfo);
                    lstSP.Add(objInfo2);
                    lstSP.Add(objInfo3);
                    lstSP.Add(objInfo4);
                    lstSP.Add(objInfo5);
                    lstSP.Add(objInfo6);
                    lstSP.Add(objInfo7);
                    lstSP.Add(objInfo8);
                    lstSP.Add(objInfo9);
                    lstSP.Add(objInfo10);
                    lstSP.Add(objInfo11);
                    lstSP.Add(objInfo12);
                    lstSP.Add(objInfo13);
                    lstSP.Add(objInfo14);


                    clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                    CSqlInfo.objParam = lstSP;

                    try
                    {
                        return int.Parse(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteReturnNonQuery("spAEUserInfoPayroll", CSqlInfo).ToString());
                    }
                    catch (System.ServiceModel.EndpointNotFoundException e)
                    {
                        e.Data.Add("My Key", "Save(IDbTransaction txn)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        return int.Parse(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteReturnNonQuery("spAEUserInfoPayroll", CSqlInfo).ToString());
                    }
                    catch (System.ServiceModel.CommunicationException e)
                    {
                        e.Data.Add("My Key", "Save(IDbTransaction txn)--:--ClsUser.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        return int.Parse(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteReturnNonQuery("spAEUserInfoPayroll", CSqlInfo).ToString());
                    }  
                   

                }
                else
                {

                    return (new VMukti.DataAccess.ClsUserDataService(txn).User_Save(ref _ID, _DisplayName, _RoleID, _FName, _LName, _EMail, _PassWord, _IsActive, _ModifiedBy, _RatePerHour, _OverTimeRate, _DoubleRatePerHour, _DoubleOverTimeRate));
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--Vmukti.Business--:--User--:--clsUser.cs--:--Save(IDbTransaction)--");
                return 0;
            }
        }

        #endregion 
    }
}
